package com.wkt.ggkt.vod.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wkt.ggkt.model.vod.Course;
import com.wkt.ggkt.result.Result;
import com.wkt.ggkt.vo.vod.CourseFormVo;
import com.wkt.ggkt.vo.vod.CoursePublishVo;
import com.wkt.ggkt.vo.vod.CourseQueryVo;
import com.wkt.ggkt.vod.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author wkt
 * @since 2022-07-05
 */
@Api(tags = "视频点播管理")
@RestController
@RequestMapping("/admin/vod/course")
//@CrossOrigin
public class CourseController {

    @Autowired
    private CourseService courseService;


    @ApiOperation("新增课程信息")
    @PostMapping("/save")
    public Result save(@RequestBody CourseFormVo courseFormVo){

        Long courseId = courseService.saveCourseInfo(courseFormVo);
        return Result.ok(courseId);
    }

    @ApiOperation("课程列表查询")
    @GetMapping("/{page}/{limit}")
    public Result findPageCourse(@PathVariable("page") Long page, @PathVariable("limit") Long limit, CourseQueryVo courseQueryVo){
        Page<Course> pageParam = new Page(page,limit);
        Map<String,Object> map = courseService.findPageCourse(pageParam,courseQueryVo);
        return Result.ok(map);
    }

    @ApiOperation("根据课程id查询")
    @GetMapping("/get/{id}")
    public Result getCourseById(@PathVariable("id") Long id){
        CourseFormVo courseFormVo = courseService.getCourseById(id);
        return Result.ok(courseFormVo);
    }

    @ApiOperation("修改课程信息")
    @PostMapping("/update")
    public Result updateCourseById(@RequestBody CourseFormVo courseFormVo){
        int result = courseService.updateCourseById(courseFormVo);
        return Result.ok(result);
    }

    @ApiOperation("根据课程id查询发布课程信息")
    @GetMapping("/getPublishCourseVo/{id}")
    public Result getPublishCourseVo(@PathVariable("id") Long id){
        CoursePublishVo publishVo = courseService.getPublishCourseVo(id);
        return Result.ok(publishVo);
    }

    @ApiOperation("发布课程信息")
    @PutMapping("/publishCourse/{id}")
    public Result publishCourse(@PathVariable("id") Long id){
        courseService.publishCourse(id);
        return Result.ok(null);
    }

    @ApiOperation("删除课程信息")
    @DeleteMapping("/removeCourse/{id}")
    public Result removeCourse(@PathVariable("id") Long id){
        courseService.removeCourse(id);
        return Result.ok(null);
    }
}

